package com.fr.chicken.controller;

import com.fr.chicken.annotation.Verification;
import com.fr.chicken.facade.base.BaseResponseDTO;
import com.fr.chicken.facade.request.*;
import com.fr.chicken.facade.response.*;
import com.fr.chicken.service.UserService;
import com.fr.chicken.util.IpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/user")
@Api(value = "/api-user", description = "用户管理")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户注册", notes = "用户注册")
    @RequestMapping(value = "/userRegister", method = RequestMethod.POST, produces = "application/json")
    public UserRegisterResponseDTO userRegister(@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UserRegisterRequsetDTO requset, HttpServletRequest httpRequest) {
        requset.setLoginIp(IpUtil.getIpAddr(httpRequest));
        UserRegisterResponseDTO response = userService.userRegister(requset);
        return response;
    }

    @Verification
    @ApiOperation(value = "后台添加用户", notes = "后台添加用户")
    @RequestMapping(value = "/insertUser", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO insertUser(@RequestHeader String accessToken, @RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) InsertUserRequsetDTO requset, HttpServletRequest httpRequest) {
        requset.setLoginIp(IpUtil.getIpAddr(httpRequest));
        BaseResponseDTO response = userService.insertUser(requset);
        return response;
    }

    @ApiOperation(value = "用户登录", notes = "用户登录")
    @RequestMapping(value = "/userLogin", method = RequestMethod.POST, produces = "application/json")
    public UserLoginResponseDTO userLogin(@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UserLoginRequsetDTO requset, HttpServletRequest httpRequest) {
        requset.setLoginIp(IpUtil.getIpAddr(httpRequest));
        UserLoginResponseDTO response = userService.userLogin(requset);
        return response;
    }

    @ApiOperation(value = "用户获取手机验证码", notes = "用户获取手机验证码")
    @RequestMapping(value = "/userGetPhoneCode/{phoneNumber}", method = RequestMethod.GET, produces = "application/json")
    public UserGetPhoneCodeResponseDTO userGetPhoneCode(@PathVariable(value = "phoneNumber") @ApiParam(required = true, value = "用户id") String phoneNumber) {
        UserGetPhoneCodeResponseDTO response = userService.userGetPhoneCode(phoneNumber);
        return response;
    }

    @Verification
    @ApiOperation(value = "查询用户列表", notes = "查询用户列表")
    @RequestMapping(value = "/getPlayerInfoList", method = RequestMethod.GET, produces = "application/json")
    public GetPlayerInfoListResponseDTO getPlayerInfoList(@RequestHeader String accessToken, GetPlayerInfoListRequsetDTO requsetDTO) {
        GetPlayerInfoListResponseDTO response = userService.getPlayerInfoList(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "查询用户信息", notes = "查询用户信息")
    @RequestMapping(value = "/getPlayerInfo/{playerId}", method = RequestMethod.GET, produces = "application/json")
    public GetPlayerInfoResponseDTO getPlayerInfo(@RequestHeader String accessToken, @PathVariable(value = "playerId") @ApiParam(required = true, value = "用户id") Long playerId) {
        GetPlayerInfoResponseDTO response = userService.getPlayerInfo(playerId);
        return response;
    }

    @Verification
    @ApiOperation(value = "封号/解封", notes = "封号/解封")
    @RequestMapping(value = "/setStatus/{playerId}", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO setStatus(@RequestHeader String accessToken, @PathVariable(value = "playerId") @ApiParam(required = true, value = "用户id") Long playerId) {
        BaseResponseDTO response = userService.setStatus(playerId);
        return response;
    }

    @Verification
    @ApiOperation(value = "开启一级代理", notes = "开启一级代理")
    @RequestMapping(value = "/setAgent/{playerId}", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO setAgent(@RequestHeader String accessToken, @PathVariable(value = "playerId") @ApiParam(required = true, value = "用户id") Long playerId) {
        BaseResponseDTO response = userService.setAgent(playerId);
        return response;
    }

    @Verification
    @ApiOperation(value = "开启总代理", notes = "开启总代理")
    @RequestMapping(value = "/setGeneralAgent/{playerId}", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO setGeneralAgent(@RequestHeader String accessToken, @PathVariable(value = "playerId") @ApiParam(required = true, value = "用户id") Long playerId) {
        BaseResponseDTO response = userService.setGeneralAgent(playerId);
        return response;
    }

    @Verification
    @ApiOperation(value = "禁言", notes = "禁言")
    @RequestMapping(value = "/setCharState", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO setCharState(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) SetCharStateRequsetDTO requsetDTO) {
        BaseResponseDTO response = userService.setCharState(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "查询绑定平台", notes = "查询绑定平台")
    @RequestMapping(value = "/queryBindPlatform", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO queryBindPlatform(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) QueryPlatformRequestDTO requsetDTO) {
        return userService.queryBindPlatform(requsetDTO.getPlayerId());
    }

    @Verification
    @ApiOperation(value = "绑定平台", notes = "绑定平台")
    @RequestMapping(value = "/bindPlatform", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO bindPlatform(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) BindPlatformRequest requsetDTO) {
        return userService.bindPlatform(requsetDTO);
    }

    @Verification
    @ApiOperation(value = "更新用户信息", notes = "更新用户信息")
    @RequestMapping(value = "/updateUserInfo", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO updateUserInfo(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UpdateUserInfoRequsetDTO requsetDTO) {
        return userService.updateUserInfo(requsetDTO);
    }

    @Verification
    @ApiOperation(value = "喊话消耗鸡蛋", notes = "喊话消耗鸡蛋")
    @RequestMapping(value = "/userMessageConsume", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO userMessageConsume(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) QueryPlatformRequestDTO requsetDTO) {
        BaseResponseDTO response = userService.userMessageConsume(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "查询用户登录日志", notes = "查询用户登录日志")
    @RequestMapping(value = "/getPlayerLoginList", method = RequestMethod.GET, produces = "application/json")
    public GetPlayerLoginListResponseDTO getPlayerLoginList(@RequestHeader String accessToken, GetPlayerLoginListRequsetDTO requsetDTO) {
        GetPlayerLoginListResponseDTO response = userService.getPlayerLoginList(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "添加激活码", notes = "添加激活码")
    @RequestMapping(value = "/insertGoodsLog", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO insertGoodsLog(@RequestHeader String accessToken,@RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) QueryPlatformRequestDTO requsetDTO) {
        BaseResponseDTO response = userService.insertGoodsLog(requsetDTO);
        return response;
    }

    @Verification
    @ApiOperation(value = "获取用户激活码列表", notes = "获取用户激活码列表")
    @RequestMapping(value = "/getUserActivationList/{playerId}", method = RequestMethod.GET, produces = "application/json")
    public GetUserActivationListResponseDTO getUserActivationList(@RequestHeader String accessToken, @PathVariable(value = "playerId") @ApiParam(required = true, value = "用户id") Long playerId) {
        GetUserActivationListResponseDTO response = userService.getUserActivationList(playerId);
        return response;
    }

    @Verification
    @ApiOperation(value = "玩家进行分享", notes = "玩家进行分享")
    @RequestMapping(value = "/share", method = RequestMethod.POST, produces = "application/json")
    public BaseResponseDTO playerShare(@RequestHeader String accessToken, @RequestBody @ApiParam(name = "json对象", value = "传入json格式", required = true) UserShareRequestDTO requsetDTO) {
        BaseResponseDTO response = userService.share(requsetDTO.getPlayerId());
        return response;
    }
}
